package com.nullpointer.xchat.fragment;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;

import com.nullpointer.xchat.R;

public class ExitConfirmDialogFragment extends DialogFragment {
	private Button btExit;
	private Button btCancel;
	private OnExitDialogListener listener;


	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_exit, container);
		findViewIds(view);
		init();
		setEvent();
		return view;
	}

	private void init() {
		getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
	}

	private void setEvent() {
		btExit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(listener != null){
					listener.onExit();
				}
			}
		});
		
		btCancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dismiss();
				if(listener != null){
					listener.onCancel();
				}
			}
		});
	}

	private void findViewIds(View view) {
		btExit = (Button)view.findViewById( R.id.bt_exit );
		btCancel = (Button)view.findViewById( R.id.bt_cancel );
	}
	
	@Override
	public void onDismiss(DialogInterface dialog) {
		super.onDismiss(dialog);
	}
	
	@Override
	public void onCancel(DialogInterface dialog) {
		super.onCancel(dialog);
	}
	
	public void setOnExitDialogListener(OnExitDialogListener listener){
		this.listener = listener;
	}
	
	public interface OnExitDialogListener{
		public void onCancel();
		public void onExit();
	}
}
